package cn.com.twoke.game.client.handler;

import cn.com.twoke.game.client.cache.ClientCacheManager;
import cn.com.twoke.game.client.games.framework.core.AcceptChatMessageAble;
import cn.com.twoke.game.client.games.framework.core.Game;
import cn.com.twoke.game.client.games.framework.ui.ChatMessage;
import cn.com.twoke.game.client.games.gomoku.GomokuGame;
import cn.com.twoke.game.common.entity.message.GameChatMessage;
import cn.com.twoke.game.common.handler.MessageHandler;

import java.io.IOException;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

public class GameChatMessageHandler implements MessageHandler<GameChatMessage> {

    @Override
    public void handle(Selector selector, SocketChannel channel, GameChatMessage message) throws IOException {
        String gameId = message.getGameId();
        Game game = ClientCacheManager.INSTANCE.getGame(gameId);
        if (null != game) {
            if (game instanceof AcceptChatMessageAble) {
                ((AcceptChatMessageAble) game).acceptMessage(new ChatMessage(message.getContent(),
                        message.getFormId(), message.getTime()));
            }
        }
    }


}
